<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加笔记</title>
    <link rel="stylesheet" href="/layui-v2.6.4/layui/css/layui.css" media="all">
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/layui-v2.6.4/layui/layui.js"></script>
</head>
<style>
    body {
        margin: 10px;
    }

    .demo-carousel {
        height: 200px;
        line-height: 200px;
        text-align: center;
    }
</style>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>新增小说</legend><span class="success" id="msg"></span>
</fieldset>
<form class="layui-form" action="" method="get">
    <div class="layui-form-item">
        <label class="layui-form-label">小说名</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="title" required lay-verify="required" placeholder="请输入小说标题"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-inline">
            <input type="text" id="author" name="author" placeholder="(选填)作者姓名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分区</label>
        <div class="layui-input-block">
            <select id="type" name="type" lay-verify="required">
                <option value=""></option>
                <option th:each="type,a : ${types}" th:value="${type}" th:text="${type}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否展示</label>
        <div class="layui-input-block">
            <input id="isdel" type="checkbox" name="isdel" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <textarea id="data" name="data"  required lay-verify="required"  placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use('form', function() {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data) {
            var isok = false;
            layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: "/addfiction"
                , type: 'get'
                , async: false
                ,data: {
                    title: $("#title").val()
                    , author: $("#author").val()
                    , type: $("#type").val()
                    , isdel: $("#isdel").val()
                    , data: $("#data").val()
                }
                , success: function (res) {
                    if(res==='ok'){
                        layer.msg(res);
                        $("#msg").html("成功")
                        isok=true;
                    }else{
                        $("#msg").html("故障了,请重试")
                    }
                }
            });
            if(isok){
                parent.layui.admin.events.closeThisTabs();
                return true;
            }
            return false;
        });
    });
</script>
</body>
</html>
